<%@page import="models.Quiz"%>
<%@page import="dao.QuizDao"%>
<%@page import="classes.Valuta"%>
<%@page import="models.User"%>
<%@include file="template/configuration.jsp" %>
<%@page import="java.util.List"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>${website} || Manage quizzes</title>
        ${stylesheet}
        ${jquery}
        ${jstooltip}
        ${jscollapse}
    </head>
    <body>
        <div class="container">
            <%@include file="template/header.jsp" %>
            <div class="content">
                <h1>Manage quizzes</h1>
                <!-- clear //-->
                <div class="clear margin-bottom-10"></div>
                <c:choose>
                    <c:when test="${fn:length(courses)!=0}">
                        <c:forEach items="${courses}" var="course">
                            <div class="bundle">
                                <div class="top">
                                    <div class="left">
                                    </div>
                                    <div class="center">
                                        <h5>${course.name}</h5>
                                    </div>
                                    <div class="right">
                                            <a href="ManageQuiz?courseid=${course.id}">Add a new quiz<img src="${url}images/add.png" /></a>
                                    </div>
                                </div>
                                <!-- clear //-->
                                <div class="clear"></div>
                                <div class="full-block">    
                                    <c:set var="catid" value="${course.id}" /> 
                                    <%
                                    //hu(mq), cd(mq), mq = manage quizes
                                    HibernateUtil humq = new HibernateUtil();
                                    QuizDao qdmq = new QuizDao(humq.openSession());
                                    HttpSession sessie = request.getSession();
                                    List<Quiz> quizListMC = null;
                                    quizListMC = qdmq.findAllbyCourse(Long.parseLong(pageContext.getAttribute("catid").toString()));
                                    request.setAttribute("quizzes", quizListMC);           
                                    if (quizListMC.size() > 0) { 
                                    %>
                                        <div>
                                            <table class="overview">
                                                <tr>
                                                    <th>Quiz</th>
                                                    <th>Description</th>
                                                    <th class="single-icon">Questions</th>                                                    
                                                    <th class="manage">Manage</th>
                                                </tr>
                                                <c:set var="i" value="0"/>
                                                <c:forEach items="${quizzes}" var="quiz">
                                                    <c:set var="i" value="${i + 1}"/>
                                                    <tr class="<c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                                                        <td>${quiz.name}</td>
                                                        <td>
                                                            <c:choose>
                                                                <c:when test="${fn:length(quiz.description) > 40}">
                                                                     <c:out value="${fn:substring(quiz.description, 0, 40)}"/>...
                                                                </c:when>
                                                                <c:otherwise>
                                                                    ${quiz.description}
                                                                </c:otherwise>
                                                            </c:choose>
                                                        </td>
                                                        <td>
                                                            <center><a href="QuizQuestion?quizid=${quiz.id}"><img src="${url}images/questions.png" /></a></center>
                                                        </td> 
                                                        <td>
                                                            <a href="ManageQuiz?idedit=${quiz.id}"><img src="${url}images/edit.png" /></a> 
                                                                <a href="ManageQuiz?idremove=${quiz.id}" class="remove"><img src="${url}images/remove.png" /></a>
                                                                <span class="info">quiz <strong>${quiz.name}</strong></span>
                                                        </td>
                                                    </tr>
                                                </c:forEach>
                                            </table>
                                        </div>
                                    <% } else { %>
                                        <div class="no-yet-message">
                                            There are no quizzes in this course yet.
                                        </div>
                                    <% } %>
                                </div>
                                <!-- clear //-->
                                <div class="clear margin-bottom-10"></div>
                            </div>
                        </c:forEach>
                    </c:when>
                    <c:otherwise>
                        <div class="full-block">
                            There are no courses at this moment.
                        </div>
                    </c:otherwise>
                </c:choose>
            </div>
            <%@include file="template/footer.jsp" %>
        </div>
    </body>
</html>
